//
//  NYMyMessageCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYMyMessageCell.h"
@interface NYMyMessageCell ()
@property (strong, nonatomic)  TTTAttributedLabel *timeLabel;
@property (strong, nonatomic)  TTTAttributedLabel *titleLabel;
@property(nonatomic, strong) NYMyMessageModel *commentModel;
@property (strong, nonatomic)  TTTAttributedLabel *commentLabel;
@property(nonatomic, strong) QMUIFillButton *fillButton;
@end
@implementation NYMyMessageCell
- (BOOL)shouldUpdateCellWithObject:(NYMyMessageModel *)object
{
        if (![object isKindOfClass:[NYMyMessageModel class]])
        {
                return NO;
        }
        [self updateContentWithModel:object];
        return YES;
}
+ (CGFloat)heightForObject:(NYMyMessageModel *)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
        return [tableView fd_heightForCellWithIdentifier:identifier cacheByIndexPath:indexPath configuration:^(NYMyMessageCell * cell) {
                [cell updateContentWithModel:object];
        }];
}
- (void)updateContentWithModel:(NYMyMessageModel *)model
{
        self.commentModel = model;
        self.titleLabel.text = NOT_NULL_STRING(self.commentModel.send_username, @"系统管理员");
        self.timeLabel.text = [AppUnit formatGMT8TimeMillisecond:model.send_time.floatValue * 1000 withFormat:@"yyyy-MM-dd HH:mm"];
        self.commentLabel.text = NOT_NULL_STRING_DEFAULT_EMPTY(model.receive_content);
        self.fillButton.hidden = (model.state.integerValue == 2);
}

- (void)setupView
{
        [super setupView];
        self.contentView.backgroundColor = UIColorForBackground;
        
        self.timeLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        self.timeLabel.font    = WGSystem12Font;
        self.timeLabel.textColor = UIColorHex(0x999999);
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        self.timeLabel.backgroundColor = UIColorForBackground;
        
        UIView *labelView = [[UIView alloc] init];
        labelView.layer.cornerRadius = 9;
        labelView.clipsToBounds = YES;
        labelView.backgroundColor = [UIColor whiteColor];
        
        self.titleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        self.titleLabel.numberOfLines = 1;
        self.titleLabel.backgroundColor = [UIColor clearColor];
        self.titleLabel.font  = WGSystem14Font;
        self.titleLabel.textColor = UIColorHex(0x333333);
        self.titleLabel.textInsets = UIEdgeInsetsMake(23, 15, 0, 18);
        
        self.fillButton = [[QMUIFillButton alloc] initWithFillType:(QMUIFillButtonColorRed)];
        self.fillButton.userInteractionEnabled = NO;
        
        self.commentLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        self.commentLabel.numberOfLines = 0;
        self.commentLabel.backgroundColor = [UIColor clearColor];
        self.commentLabel.font  = WGSystem13Font;
        self.commentLabel.textInsets = UIEdgeInsetsMake(0, 15, 20, 12);
        self.commentLabel.textColor = UIColorHex(0x666666);
        
        UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.titleLabel,self.commentLabel]];
        stackView.axis = UILayoutConstraintAxisVertical;
        stackView.distribution = UIStackViewDistributionFillProportionally;
        stackView.alignment = UIStackViewAlignmentFill;
        stackView.spacing = __WGHeight(13);
        [labelView addSubview:stackView];
        
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:labelView];
        [labelView addSubview:self.fillButton];
        
        
        
        [stackView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(labelView);
        }];
        
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.left.right.equalTo(self.contentView);
                make.height.mas_equalTo(__WGHeight(40));
        }];
        
        [labelView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.timeLabel.mas_bottom);
                make.left.equalTo(self.contentView).offset(__WGWidth(15.0f));
                make.right.equalTo(self.contentView).offset(__WGWidth(-15.0f));
                make.bottom.equalTo(self.contentView);
        }];
        
        [self.fillButton mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.titleLabel);
                make.right.equalTo(labelView.mas_right).offset(-__WGWidth(15));
                make.height.width.mas_equalTo(7);
        }];
}

@end
